package live.ifox.factory;

import android.content.Context;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ContextInfo {
    private List<Map<String, Object>> infoModel;
    private Context mContext;

    public ContextInfo(Context context) {
        this.mContext = context;
        infoModel = new ArrayList<>();
    }

    private void addItem(String label, Object detail) {
        Map<String, Object> map = new HashMap<>();
        map.put("label", label);
        map.put("detail", detail);
        infoModel.add(map);
    }

    public List<Map<String, Object>> getModel() {
        addItem("Cache", mContext.getCacheDir().getAbsolutePath());
        // addItem("Databases",mContext.getDataDir().getAbsolutePath());
        addItem("Files", mContext.getFilesDir().getAbsolutePath());
        addItem("Obb", mContext.getObbDir().getAbsolutePath());
        addItem("packageName", mContext.getPackageName());
        addItem("packageCodePath", mContext.getPackageCodePath());
        addItem("packageResourcePath", mContext.getPackageResourcePath());
        StringBuilder builder = new StringBuilder();
        for (String file : mContext.fileList()) {
            builder.append(file);
            builder.append(";");
        }
        addItem("Files", builder.toString());

        builder = new StringBuilder();
        for (String file : mContext.databaseList()) {
            builder.append(file);
            builder.append(";");
        }
        addItem("Databases", builder.toString());

        return infoModel;
    }
}
